package org.lintcode_Close.Stage1_Easy_50.O6简单递归;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: qingle
 * @Date: 2024/8/20-21:51
 * @Description:
 * @version: 1.0
 */
public class 二叉树的后序遍历 {

	public static void main(String[] args) {


	}

 public class TreeNode {
	 public int val;
	 public TreeNode left, right;

	 public TreeNode(int val) {
		 this.val = val;
		 this.left = this.right = null;
	 }
 }

	public List<Integer> postorderTraversal(TreeNode root) {
		// write your code here
		List<Integer> result = new ArrayList<>();
		postOrder(root, result);
		return result;
	}

	// 递归实现前序遍历
	private void postOrder(TreeNode node, List<Integer> result) {
		if (node == null) return;

		postOrder(node.left, result);
		postOrder(node.right, result);
		result.add(node.val);
	}
}
